package com.lfx.data.map;

import java.util.HashMap;

/**
 * @author 李逢喜
 * create 2021/7/15
 */
public class MyHashMap {

    private ListNode[] map=new ListNode[8];

    private int size;


    public boolean put(String key,String value){
        //需要扩容
        if(size>=map.length*0.75) return false;

        int index=Math.abs(key.hashCode())%map.length;

        ListNode node = map[index];
        if(node==null){//下标所在位置首次插入数据
            Node head=new Node(key,value,null);

            ListNode listNode=new ListNode();
            listNode.head=head;
            map[index]=listNode;
        }else {//非首次
            node.addNode(key,value);
        }

        return true;

    }



    public String get(String key){
        int index=Math.abs(key.hashCode())%map.length;
        ListNode listNode = map[index];
        if(listNode==null)return null;


        return listNode.getVal(key);
    }


    public static void main(String[] args) {
        MyHashMap map=new MyHashMap();
        map.put(""+1,"s22ss");
        map.put("key1","sss");
        map.put("key1","bbbb");
        System.out.println(map.get("1"));
    }
}
